﻿﻿﻿﻿﻿@extends('admin.Default')
@section('type')
    <!-- Data Tables -->
    <link href="{{ asset('myadmin/css/plugins/summernote/summernote.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/summernote/summernote-bs3.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/dropzone/basic.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/dropzone/dropzone.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/iCheck/custom.css') }}" rel="stylesheet">
        <style>

            .ibox-content {
                float: none;
                display: block;
                margin-left: auto;
                margin-right: auto;
            }

        </style>
@stop
@section('content')
            <div class="ibox float-e-margins">
                <div class="ibox-content col-md-8">
        <form action="/store/product" method="post" enctype='multipart/form-data'>
        <div class="form-group row">
            <label class="col-sm-2 control-label">药品名：</label>
            <div class="col-sm-6 ">
                <input type="text" name="name" class="form-control" placeholder="请输入药品名">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 control-label">单价：</label>
            <div class="col-sm-6">
                <input type="text" name="price" class="form-control" data-mask="¥ 999,999,999.99" placeholder="888,888.88">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 control-label">品牌名：</label>
            <div class="col-sm-6">
                <input type="text" name="brand" class="form-control" placeholder="请输入所属品牌">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 control-label">库存：</label>
            <div class="col-sm-6">
                <input type="text" name="stock" class="form-control" placeholder="请输入药品库存量">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 control-label">规格：</label>
            <div class="col-sm-6">
                <input type="text" name="specifications" class="form-control" placeholder="请输入药品的规格">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 control-label">状态：</label>
            <div class="col-sm-4">
                <label class="radio-inline">
                    <input type="radio" checked="" value="1" id="optionsRadios1" name="status">上架</label>
                <label class="radio-inline">
                    <input type="radio" value="2" id="optionsRadios2" name="status">下架</label>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 control-label">是否为处方药：</label>
            <div class="col-sm-4">
                <label class="radio-inline">
                    <input type="radio" checked="" value="1" id="optionsRadios1" name="nature">处方药</label>
                <label class="radio-inline">
                    <input type="radio" value="2" id="optionsRadios2" name="nature">非处方药</label>
            </div>
        </div>
        <div class=" form-group row" id="c_div">
            <div class="form-group">
                <label class="col-sm-2 control-label">前台分类：</label>
                <div class="col-sm-10">
                    <select id='cid' name="type">
                        <option >--请选择--</option>

                    </select>
                </div>
            </div>
        </div>
        <div class="col-sm-12 row" id="type_div">

        </div>
        <div class=" form-group row" id="d_div">
            <div class="form-group">
                <label class="col-sm-2 control-label">药品分类：</label>
                <div class="col-sm-10">
                    <select  name="select[1]" id='did'>
                        <option >--请选择--</option>

                    </select>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins border-bottom">
                    <div class="ibox-title">
                        <h5>药品功能简介</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-down"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="form_editors.html#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">

                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content no-padding" style="display: none;">


                        <div class="note-editor form-group">


                            <textarea class="note-editor form-control" name="summary" rows="3" ></textarea>

                        </div>

                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins border-bottom">
                    <div class="ibox-title">
                        <h5>药品说明书</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-down"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="form_editors.html#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                                <li><a href="form_editors.html#">选项1</a>
                                </li>
                                <li><a href="form_editors.html#">选项2</a>
                                </li>
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content no-padding" style="display: none;">


                        <div class="note-editor form-group">


                            <textarea class="note-editor form-control" name="instructions" rows="3" ></textarea>

                        </div>

                    </div>
                </div>
            </div>
        </div>
            <input type='hidden' name='_token' value='{{ csrf_token() }}'>

            <div class="list list-title" id="img_div">


                    <i>轮播图：</i>

                <input style="display: none" type="file" id="imgs" name="file[]" multiple="multiple">
                <button type="button" onclick="demo1();"  >点击上传<br></button>


            </div>
            <button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit"
            ><strong>提交</strong>
            </button>
        </form>
    </div>
            </div>

@stop
@section('script')
    <!-- SUMMERNOTE -->
    <script src="{{ asset('myadmin/js/plugins/summernote/summernote.min.js') }}"></script>
    <script src="{{ asset('myadmin/js/plugins/summernote/summernote-zh-CN.js') }}"></script>
    <script src="{{ asset('myadmin/js/plugins/dropzone/dropzone.js') }}"></script>

    <script id="script">
        function category() {
            $.ajax({
                url: '/store/product/categroy',
                async: true,				//是否异步
                type: 'post',				//请求方式
                data: {pid: 0, _token: "{{ csrf_token() }}"},				//发送的数据
                dataType: 'json',			//响应的数据类型
                error: function ()			//失败时回调函数
                {
                    alert('ajax请求失败');
                },
                success: function (data)		//成功时回调函数
                {
                    //console.log(data);
                    for (var i = 0; i < data.length; i++) {
                        $('#did').append("<option value='" + data[i].id + "'>" + data[i].name + "</option>");
                    }
                    ;
                }
            });
        }

        $('#d_div').on("change","select",function(){

            //先清除后面的select，再添加新的select
            $(this).nextAll("select").remove();
            //因为下面需要用到当前对象，但是是另一个函数体内，不能用$(this)
            var ob = $(this);
            //判断选择的是不是默认的请选择
            if($(this).val() != '--请选择--'){
                var pid = $(this).val();
                $.ajax({
                    url:'/store/product/categroy',
                    async:false,				//是否异步
                    type:'post',				//请求方式
                    data:{pid:pid,_token: "{{ csrf_token() }}"},				//发送的数据
                    dataType:'json',			//响应的数据类型
                    error:function()			//失败时回调函数
                    {
                        alert('ajax请求失败');
                    },
                    success:function(data)		//成功时回调函数
                    {

                        //判断是否还有数据返回
                        if(data.length>0){
                            //新建一个select标签
                            var select = $("<select name=select["+(data[0].path.split(',').length-1)+"] ><option>--请选择--</option></select>");
                            //循环给select标签添加上option
                            for (var i = 0; i < data.length; i++) {
                                $(select).append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
                            };
                            console.log($(select));
                            //追加到前一个select后面
                            ob.after(select);
                        }
                    }
                });
            }

        });

        $.ajax({
            url:'/store/product/type',
            async:true,				//是否异步
            type:'post',				//请求方式
            data:{type_id:0,_token: "{{ csrf_token() }}"},				//发送的数据
            dataType:'json',			//响应的数据类型
            error:function()			//失败时回调函数
            {
                alert('ajax请求失败');
            },
            success:function(data)		//成功时回调函数
            {
                category();
                for (var i = 0; i < data.length; i++) {
                    $('#cid').append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
                };
            }
        });

        $('#c_div').on("change","select",function(){
            //先清除后面的select，再添加新的select
            $('#type_div').children('label').remove();
            //因为下面需要用到当前对象，但是是另一个函数体内，不能用$(this)
            var ob = $(this);
            //判断选择的是不是默认的请选择
            if($(this).val() != '--请选择--'){
                var type_id = $(this).val();
                $.ajax({
                    url:'/store/product/type',
                    async:false,				//是否异步
                    type:'post',				//请求方式
                    data:{type_id:type_id,_token: "{{ csrf_token() }}"},				//发送的数据
                    dataType:'json',			//响应的数据类型
                    error:function()			//失败时回调函数
                    {
                        alert('ajax请求失败');
                    },
                    success:function(data)		//成功时回调函数
                    {

                        //判断是否还有数据返回
                        if(data.length>0){
                            //新建一个select标签
                            //var select = $("<select name='select[2]' multiple='multiple' ><option>--请选择--</option></select>");
//
                            for (var i = 0; i < data.length; i++) {
                                $('#type_div').append('<label class="checkbox-inline i-checks col-sm-3"><input type="checkbox" name="label['+i+']" value='+data[i].name+' style="position: absolute;"></div>'+data[i].name+'</label>');


                            };


                        }
                    }
                });
            }

        });
        function demo(){
            $("#img").click();  //隐藏了input:file样式后，点击头像就可以本地上传
            $("#img").on("change",function(){
                var objUrl = getObjectURL(this.files[0]) ; //获取图片的路径，该路径不是图片在本地的路径
                if (objUrl) {
                    $("#pic").attr("src", objUrl) ; //将图片路径存入src中，显示出图片
                }
            });
        }


        //建立一個可存取到該file的url
        function getObjectURL(file) {

            var url = null ;
            if (window.createObjectURL!=undefined) { // basic

                url = window.createObjectURL(file) ;
            } else if (window.URL!=undefined) { // mozilla(firefox)

                url = window.URL.createObjectURL(file) ;
            } else if (window.webkitURL!=undefined) { // webkit or chrome

                url = window.webkitURL.createObjectURL(file) ;
            }
            return url ;
        }
        var y =0;
        function demo1(){
            $("#imgs").click();  //隐藏了input:file样式后，点击头像就可以本地上传
            $("#imgs").on("change",function(){
                var img = '';
                var flength = this.files.length;
                //alert(flength);
                for(var i=0;i<flength;i++){
                    var objUrl = getObjectURL(this.files[i]) ; //获取图片的路径，该路径不是图片在本地的路径
                    if (objUrl) {

                        img =img+"<img  src="+objUrl+" width='80'>";
                    }
                    y++;
                }
                $('#img_div').children('img').remove();
                $('#img_div').append(img);
            });
        }
    </script>

    <script>
        $(document).ready(function () {

            $('.i-checks').iCheck({checkboxClass:'icheckbox_square-green',radioClass:'iradio_square-green',})

            $('.summernote').summernote({
                lang: 'zh-CN'
            });

        });
        var edit = function () {
            $("#eg").addClass("no-padding");
            $('.click2edit').summernote({
                lang: 'zh-CN',
                focus: true
            });
        };
        var save = function () {
            $("#eg").removeClass("no-padding");
            var aHTML = $('.click2edit').code(); //save HTML If you need(aHTML: array).
            $('.click2edit').destroy();

        };
    </script>
    <script>
        $(document).ready(function () {

            $("#doctorForm").validate({
                rules: {
                    name: {
                        required: true,
                    },
                    price: {
                        required: true,
                        number:true,
                    },
                    brand: {
                        required: true,
                    },
                    stock: {
                        required: true,
                        number: true,
                    },

                    summary: {
                        required: true,
                    },

                    insstructions: {
                        required: true,
                    },
                }
            });
        });
    </script>

@stop
